package com.easylinkin.linkappapi.investigation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easylinkin.linkappapi.investigation.entity.InvestigationTaskModelContent;
import com.easylinkin.linkappapi.investigation.mapper.InvestigationTaskModelContentMapper;
import com.easylinkin.linkappapi.investigation.service.InvestigationTaskModelContentService;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 排查任务模板内容 服务实现类
 * </p>
 *
 * @author TongJie
 * @since 2021-04-15
 */
@Service
public class InvestigationTaskModelContentServiceImpl extends ServiceImpl<InvestigationTaskModelContentMapper, InvestigationTaskModelContent> implements InvestigationTaskModelContentService {
    @Resource
    LinkappUserContextProducer linkappUserContextProducer;
    /**
     * 根据模板ID查询
     * */
    @Override
    public List<InvestigationTaskModelContent> listByInvestigationTaskModelId(Long investigation_task_model_id) {
        Assert.notNull(investigation_task_model_id,"investigation_task_model_id 参数为空");
        QueryWrapper<InvestigationTaskModelContent> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("investigation_task_model_id",investigation_task_model_id);
        queryWrapper.eq("tenant_id", linkappUserContextProducer.getNotNullCurrent().getTenantId());
        queryWrapper.orderByAsc("sort_no");
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据模板类型ID查询
     * */
    @Override
    public  Integer countByInvestigationTypeIds(List<Long>  investigation_type_ids) {
        Assert.notEmpty(investigation_type_ids,"investigation_task_model_ids 参数为空");
        QueryWrapper<InvestigationTaskModelContent> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("investigation_type_id",investigation_type_ids);
        queryWrapper.eq("tenant_id", linkappUserContextProducer.getNotNullCurrent().getTenantId());
        return baseMapper.selectCount(queryWrapper);
    }

    /**
     * 根据模板ID删除
     * */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public  void deleteByInvestigationTaskModelIds(List<Long>  investigation_task_model_ids) {
        Assert.notEmpty(investigation_task_model_ids,"investigation_task_model_ids 参数为空");
        QueryWrapper<InvestigationTaskModelContent> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("investigation_task_model_id",investigation_task_model_ids);
        queryWrapper.eq("tenant_id", linkappUserContextProducer.getNotNullCurrent().getTenantId());
        baseMapper.delete(queryWrapper);
    }
}
